//
//  HotManager.m
//  FreeReading
//
//  Created by lanou3g on 15/11/3.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "HotManager.h"
#import "HotModel.h"

#define kNewsUrl @"http://api.huceo.com/wxnew/other/?key=f568c58143884294f9ccbcb8d7aeb927&num=50"

@implementation HotManager

+(HotManager *)shareManager
{
    static HotManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[[self class] alloc] init];
    });
    return manager;
}

- (void)requestDataForReloadWithBlock:(void(^)(NSMutableArray *array))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];
        [manager GET:kNewsUrl parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
            NSMutableArray *tempArray = [NSMutableArray array];
            NSArray *array = responseObject[@"newslist"];
            for (NSDictionary *dic in array) {
                
                HotModel *model = [[HotModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                
                [tempArray addObject:model];
                
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                block(tempArray);
            });
            
        } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
            
        }];
    });
}

@end
